/*************************************************************************
	> File Name: 024.swapPairs.c
	> Author: Maureen 
	> Mail: Maureen@qq.com 
	> Created Time: 四  9/ 2 12:59:56 2021
 ************************************************************************/

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */

struct ListNode* swapPairs(struct ListNode* head){
    if (head == NULL || head->next == NULL) return head;
    struct ListNode *p = (struct ListNode *)malloc(sizeof(struct ListNode));
    p->next = head;
    struct ListNode *now = p;
    while (now->next && now->next->next) {
        struct ListNode *l = now->next, *r= now->next->next;
        now->next = r;
        l->next = r->next;
        r->next = l;
        now = l;
    }
    return p->next;
}
